package com.foreknow.demo4;

public class Master {

    public void feed(Pet pet){
        pet.eat();
    }

    public void cure(Pet pet){
        if(pet.getHealth()<50){
            pet.toHospital();
            System.out.println("吃药。。。。。。");
        }
    }

    public void play(Pet pet){
        if (pet instanceof Dog){
            Dog d = (Dog) pet;
            d.run();
        }else if (pet instanceof  Penguin){
            Penguin p = (Penguin) pet;
            p.swimming();
        }
    }

    public static void main(String[] args) {
        Master master = new Master();
        Dog d = new Dog();
        d.setName("花花");
        d.setHealth(40);
        d.setLove(99);
        master.cure(d);
        master.feed(d);
        master.play(d);

        Penguin p = new Penguin();
        p.setName("QQ");
        p.setHealth(20);
        p.setLove(100);
        master.cure(p);
        master.feed(p);
        master.play(p);
    }
}
